import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isEmpty from "lodash/isEmpty";

var _dec, _dec2, _dec3, _class;

/**
 * DataDimensionTab - 安全组数据权限维度
 * @date: 2019-11-28
 */
import React, { Component } from 'react';
import { Table, Row, Col, Checkbox as OriginCheckbox, Radio } from 'antd';
import { Bind } from 'lodash-decorators';
import intl from 'utils/intl';
import Checkbox from 'components/Checkbox';
import styles from "./index.less?modules";
var CheckboxGroup = OriginCheckbox.Group;
var RadioGroup = Radio.Group;
var DataDimensionTab = (_dec = Bind(), _dec2 = Bind(), _dec3 = Bind(), (_class = /*#__PURE__*/function (_Component) {
  _inherits(DataDimensionTab, _Component);

  var _super = _createSuper(DataDimensionTab);

  function DataDimensionTab(props) {
    var _this;

    _classCallCheck(this, DataDimensionTab);

    _this = _super.call(this, props);
    _this.state = {
      currentAuthScope: null,
      // 当前选中的范围
      authUserDefaultValue: null,
      // 数据为用户范围时的选中值
      authDefaultValue: [],
      // 权限维度默认选中的列表
      bizRoleAuthorityLines: [],
      userRoleAuthorityLines: [],
      currentRow: {}
    };
    return _this;
  }

  _createClass(DataDimensionTab, [{
    key: "columns",
    get: function get() {
      return [{
        title: intl.get('ciam.roleManagement.model.role.docType').d('单据'),
        dataIndex: 'docTypeName'
      }, {
        title: intl.get('ciam.roleManagement.model.role.authRang').d('权限维度范围'),
        dataIndex: 'authScopeMeaning'
      }];
    }
  }, {
    key: "onRow",
    value: function onRow(record) {
      this.setState({
        currentRow: record
      });
      var _record$secGrpDclDimL = record.secGrpDclDimLineList,
          secGrpDclDimLineList = _record$secGrpDclDimL === void 0 ? [] : _record$secGrpDclDimL,
          authScopeCode = record.authScopeCode;
      var authDefaultValue = [];
      var bizRoleAuthorityLines = record.secGrpDclDimLineList && record.secGrpDclDimLineList.filter(function (item) {
        return item.dimensionType === 'BIZ';
      }) || [];
      var userRoleAuthorityLines = record.secGrpDclDimLineList && record.secGrpDclDimLineList.filter(function (item) {
        return item.dimensionType === 'USER';
      }) || [];

      if (secGrpDclDimLineList) {
        authDefaultValue = secGrpDclDimLineList.filter(function (item) {
          return !!item.secGrpDclDimLineCheckedFlag;
        }).map(function (item) {
          return item.authTypeCode;
        });
      }

      var authUserDefaultValue = secGrpDclDimLineList && secGrpDclDimLineList.filter(function (item) {
        return item.dimensionType === 'USER' && !!item.secGrpDclDimLineCheckedFlag;
      }).map(function (item) {
        return item.authTypeCode;
      })[0] || [];
      this.setState({
        authDefaultValue: authDefaultValue,
        authUserDefaultValue: authUserDefaultValue,
        currentAuthScope: authScopeCode,
        bizRoleAuthorityLines: bizRoleAuthorityLines,
        userRoleAuthorityLines: userRoleAuthorityLines
      });
    }
    /**
     * 高亮显示选中行
     * @param {object} record - 行数据
     */

  }, {
    key: "addHighlight",
    value: function addHighlight(record) {
      var currentRow = this.state.currentRow;
      return "".concat(record.docTypeId, "-").concat(record.authScopeCode) === "".concat(currentRow.docTypeId, "-").concat(currentRow.authScopeCode) ? styles['auth-row-hover'] : '';
    }
  }, {
    key: "renderAuthDim",
    value: function renderAuthDim() {
      var _this$state = this.state,
          currentRow = _this$state.currentRow,
          currentAuthScope = _this$state.currentAuthScope,
          authDefaultValue = _this$state.authDefaultValue,
          authUserDefaultValue = _this$state.authUserDefaultValue,
          bizRoleAuthorityLines = _this$state.bizRoleAuthorityLines,
          userRoleAuthorityLines = _this$state.userRoleAuthorityLines;
      var emptyComponent = /*#__PURE__*/React.createElement("h3", {
        style: {
          color: 'gray'
        }
      }, intl.get('ciam.securityGroup.view.title.secGrp.empty').d('暂无数据'));
      if (_isEmpty(currentRow) || !currentAuthScope) return emptyComponent; // 未选中行或权限维度范围没有值时，不显示权限值

      if (!_isEmpty(currentRow)) {
        if (currentAuthScope === 'USER') {
          return _isEmpty(userRoleAuthorityLines) ? emptyComponent : /*#__PURE__*/React.createElement(RadioGroup, {
            value: authUserDefaultValue,
            onChange: this.authOnChange,
            style: {
              width: '100%'
            }
          }, /*#__PURE__*/React.createElement(Row, null, userRoleAuthorityLines.map(function (item) {
            return /*#__PURE__*/React.createElement(Col, {
              span: 24,
              key: item.authTypeCode
            }, /*#__PURE__*/React.createElement(Radio, {
              value: item.authTypeCode,
              key: item.authTypeCode,
              style: {
                height: 30
              },
              disabled: true
            }, item.authTypeMeaning));
          })));
        } else {
          return _isEmpty(bizRoleAuthorityLines) ? emptyComponent : /*#__PURE__*/React.createElement(CheckboxGroup, {
            style: {
              width: '100%'
            } // onChange={this.authOnChange}
            ,
            value: authDefaultValue
          }, /*#__PURE__*/React.createElement(Row, null, bizRoleAuthorityLines.map(function (item) {
            return /*#__PURE__*/React.createElement(Col, {
              span: 24,
              key: item.authTypeCode
            }, /*#__PURE__*/React.createElement(Checkbox, {
              style: {
                height: 30
              },
              key: item.authTypeCode,
              value: item.authTypeCode,
              disabled: true
            }, item.authTypeMeaning));
          })));
        }
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          dataSource = _this$props.dataSource,
          loading = _this$props.loading,
          pagination = _this$props.pagination;
      return /*#__PURE__*/React.createElement(Row, {
        gutter: 24
      }, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(Table, {
        rowKey: "docTypeId",
        loading: loading,
        dataSource: dataSource,
        columns: this.columns,
        bordered: true,
        pagination: pagination,
        rowClassName: this.addHighlight,
        onRow: function onRow(record) {
          return {
            onClick: function onClick() {
              return _this2.onRow(record);
            }
          };
        }
      })), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement("div", {
        className: styles['authDims-container']
      }, intl.get('ciam.roleManagement.view.title.authDims').d('权限值')))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement("div", {
        className: styles['authDims-item']
      }, this.renderAuthDim()))))));
    }
  }]);

  return DataDimensionTab;
}(Component), (_applyDecoratedDescriptor(_class.prototype, "onRow", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "onRow"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "addHighlight", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "addHighlight"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "renderAuthDim", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "renderAuthDim"), _class.prototype)), _class));
export { DataDimensionTab as default };